package com.repair.order.utils;

import org.redisson.api.RAtomicLong;
import org.redisson.api.RedissonClient;
import org.springframework.boot.CommandLineRunner;

/**
 * @author chunyu
 * @since 2024/10/2,16:25
 * 每次启动的时候
 */
public class WorkerId implements CommandLineRunner {

    private RedissonClient redissonClient;

    private static final String clientName = "order.client.name:workerId";

    public static long WORKER_ID;

    public WorkerId(RedissonClient redissonClient) {
        this.redissonClient = redissonClient;
    }

    @Override
    public void run(String... args) throws Exception {
        RAtomicLong workerId = redissonClient.getAtomicLong(clientName);
        System.out.println(workerId);
        WORKER_ID = workerId.incrementAndGet() % 32;
    }
}
